package com.juzhencms.apps.busi.api.accesstoken;

import java.util.Map;

import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.juzhencms.apps.base.busi.api.BaseApi;
import com.juzhencms.apps.base.busi.service.WeixinApiService;

import lombok.extern.slf4j.Slf4j;

@Slf4j
@Service("api.yunguoApi")
public class YunguoApi implements BaseApi{

	@Override
	public String getAccessToken(String appId, String appSecret) {
		// TODO Auto-generated method stub
		PostMethod postMethod = new PostMethod("http://weixin.c-cee.com/get_token") ;
    	postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
    	//参数设置，需要注意的就是里边不能传NULL，要传空字符串
    	NameValuePair[] data = {
    		new NameValuePair("app_id","wx061c0bfd528a15b7"),
    	};
    	postMethod.setRequestBody(data);
    	try {
    		org.apache.commons.httpclient.HttpClient httpClient = new org.apache.commons.httpclient.HttpClient();
    		httpClient.executeMethod(postMethod);
        	String result = postMethod.getResponseBodyAsString() ;
        	Map resultMap=JSON.parseObject(result, Map.class);
        	if(resultMap!=null && resultMap.get("access_token")!=null) {
        		return resultMap.get("access_token").toString();
        	}
    	}catch(Exception e) {
    		log.error(e.getMessage(),e);
    	}
    	return null;
	}

}
